"""
@Project ：HaloInterfaceProject 
@File    ：CreateArticleCategories.py
@IDE     ：PyCharm 
@Author  ：张成龙
@Date    ：2024/10/23 10:33 
@explain ：创建文章分类
"""
import requests

from api import SYSTEM_URL, SESSION
from utils.FakerDataUtil import FakerDataUtil


class CreateCategoriesType:

    def __init__(self):
        self.url = SYSTEM_URL + "/apis/content.halo.run/v1alpha1/categories"
        self.headers = {
            'Cookie': SESSION
        }
        self.name = FakerDataUtil.faker_user_name()

    def create_categories_type(self):

        payload = {
            "spec": {
                "displayName": self.name,
                "slug": self.name,
                "description": "",
                "cover": "",
                "template": "",
                "postTemplate": "",
                "priority": 0,
                "children": [],
                "preventParentPostCascadeQuery": False
            },
            "status": {},
            "apiVersion": "content.halo.run/v1alpha1",
            "kind": "Category",
            "metadata": {
                "name": "",
                "generateName": "category-",
                "annotations": {}
            }
        }
        response = requests.post(self.url, headers=self.headers, json=payload)

        return response
